package com.xxx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxx.mapper.DishMapper;
import com.xxx.pojo.ClassInfo;
import com.xxx.pojo.Dish;
import com.xxx.service.DishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DishServiceImpl extends ServiceImpl<DishMapper,Dish> implements DishService {

    @Autowired
    private DishMapper mapper;

    @Override
    public IPage getByPage(IPage iPage,String name) {

        LambdaQueryWrapper<Dish> lqw = new LambdaQueryWrapper<>();
        lqw.like(null != name && !"".equals(name.trim()),Dish::getName,name).orderByAsc(Dish::getOrder);

        IPage page = mapper.selectPage(iPage, lqw);

        return page;
    }

    @Override
    public int updateStatus(List<Long> ids, Integer status) {
        LambdaUpdateWrapper<Dish> luw = new LambdaUpdateWrapper<>();
        luw.set(Dish::getStatus,status).in(Dish::getId,ids);
        int update = 0;
        update = mapper.update(null, luw);
        return update;
    }
}
